<?php

namespace App\Repositories\Policy\Eloquent;

use Curl\CurlService\CurlService;
use Illuminate\Support\Facades\Redis;

class HbGjRepository
{

    protected $baseUrl = 'https://partner.huoli.com';
    protected $clientId = 'fxhengbosj';
    protected $secret = '15736996622';

    /**
     * 获取access_token
     * @return mixed
     */
    protected function getAccessToken(){

        $data = Redis::get('hbgj_access_token');
        if (!$data) {

            $url = $this->baseUrl.'/distribution/api/oauth/token?grant_type=client_credentials&client_id='.$this->clientId.'&client_secret='.$this->secret;

            $res = CurlService::get($url);

            if ($res && isset($res['data'])) {

                $data = $res['data'];
                Redis::set('hbgj_access_token',json_encode($data));
            }
        } else {

            $data = json_decode($data,true);

        }

        return $data;
    }

    /**
     * Post请求
     * @param $url
     * @param $param
     * @return void
     */
    public function postRequest($url,$param){

        $res = CurlService::post($this->baseUrl.$url,$param);

        return $res;
    }
}